package com.rickpan.task;

import com.rickpan.service.PasswordResetService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 密码重置验证码清理定时任务
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class PasswordResetCleanupTask {

    private final PasswordResetService passwordResetService;

    /**
     * 每小时清理一次过期的验证码
     */
    @Scheduled(fixedRate = 3600000) // 1小时 = 3600000毫秒
    public void cleanupExpiredCodes() {
        log.info("开始清理过期的密码重置验证码");
        try {
            passwordResetService.cleanupExpiredCodes();
            log.info("过期验证码清理完成");
        } catch (Exception e) {
            log.error("清理过期验证码失败", e);
        }
    }
}
